var talk = new Talk();
talk.talk_type = 1;

layui.define(["table", "form", "admin", 'upload'], function (exports) {
    var $ = layui.$, form = layui.form,upload = layui.upload;
    //输入框监听事件
    talk.elem.write.on({
        keydown: function (ev) {
            var e = ev || window.event;
            if (e.keyCode == 13 && !(e.shiftKey) && !(e.ctrlKey) && !(e.metaKey)) {
                e.preventDefault();
                talk.send.text();
            }
            // textarea输入框换行
            if (e.ctrlKey && e.keyCode == 13) {
                talk.elem.write.val(talk.elem.write.val() + "\n")
            }
        },
    });

    upload.render({
        elem: '#send_img',
        auto: false,
        accept: 'images',
        exts: 'png|jpg|jpeg|gif',
        size: 1024 * 1024,
        choose: function (obj) {
            layer.load();
            var choosefile;
            obj.preview(function (index, file, result) {
                choosefile = file;
            });
            document.getElementById("send_img_sbumit").reset();

            $.ajax({
                type: "POST", //请求方式
                url: '/admin/groupchat/signForCos', //请求地址
                dataType: "json", //返回的数据类型
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        var cos = new COS({
                            getAuthorization: function (options, callback) {
                                var credentials = data.data.credentials;
                                callback({
                                    TmpSecretId: credentials.tmpSecretId,
                                    TmpSecretKey: credentials.tmpSecretKey,
                                    XCosSecurityToken: credentials.sessionToken,
                                    ExpiredTime: data.data.expiredTime
                                });
                            }
                        });
                        cos.putObject({
                            Bucket: data.data.bucket,
                            Region: data.data.region,
                            Key: 'images/' + data.data.filename + choosefile.name,
                            Body: choosefile,
                        }, function (err, res) {
                            layer.closeAll('loading');
                            if (err) {
                                layer.msg("上传失败", {icon: 5});
                            } else {
                                if (res.statusCode == 200) {
                                    //layer.msg('上传成功', {icon: 1, time: 2000});
                                    //$("#icon").val("https://" + res.Location);
                                    $.ajax({
                                        type: "POST", //请求方式
                                        url: '/admin/groupchat/send_chat', //请求地址
                                        dataType: "json", //返回的数据类型
                                        data:{img: "https://" + res.Location, group_id: talk.group_info.id},
                                        //请求成功
                                        success: function (data) {
                                            if (data.code == 0) {
                                                layer.msg('图片发送成功', {icon: 1, time: 2000});
                                            } else {
                                                layer.msg("图片发送失败", {icon: 5});
                                            }
                                        }
                                    });
                                } else {
                                    layer.msg("图片上传失败", {icon: 5});
                                }
                            }
                        });
                    } else {
                        layer.closeAll('loading');
                        layer.msg(data.msg, {icon: 5});
                    }
                },
                //请求失败
                error: function (e) {
                    layer.closeAll('loading');
                    layer.msg('上传出现异常,请稍后再试', {icon: 2});
                }
            });
        }
    });

    // 左侧会话列表点击切换
    $('body').on('click', '.chatList dd', function () {
        var chat_html_obj = $('#oneChatBaseInfo');
        chat_html_obj.data($(this).data());

        talk.group_info.id = chat_html_obj.data('groupid');
        talk.group_info.name = chat_html_obj.data('groupname');
        talk.anchor.id = chat_html_obj.data('anchorid');
        talk.anchor.nick_name = chat_html_obj.data('anchorname');
        $('.chatList dd').removeClass('active');
        $(this).addClass('active');
        $("#group_read_" + talk.group_info.id).remove();
        talk.init();
        // 获取右侧群信息，方法在另外一个文件里面
        getGroupInfo(talk.group_info.id);
        //右侧用户列表信息
        getGroupUser();

        if ($('.groupInfo').hasClass('layui-hide')) {
            $('.groupInfo').removeClass('layui-hide');
            $('.chatUserArea').addClass('show_group');
        }
    })

    // 搜索主播
    $('.groupInfo .user_search input').on({
        keydown: function (ev) {
            var e = ev || window.event;
            if (e.keyCode == 13) {
                e.preventDefault();
                getGroupUser($(this).val());
            }
        },
    });

    $('.groupInfo .user_search #group_user_list_search').click(function () {
        getGroupUser($("#group_user_list_input").val());
    });

    //发送消息
    form.on('submit(expert-edit)', function (obj) {
        talk.send.text();
    });


    //解散群聊
    $('.dissolveGroupBtn').click(function () {
        layer.confirm('确定要解散该群聊吗？', function (index) {
            layer.load();
            $.ajax({
                url: '/admin/groupchat/dissolve',
                type: 'post',
                dataType: 'json',
                data: {group_id: talk.group_info.id},
                success: function (res) {
                    layer.closeAll("loading");
                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, status, error) {

                },
                complete: function (xhr, status) {
                    layer.closeAll("loading");
                }
            });
        });
    })

    //编辑群组
    $('body').on('click', '.editGroupBtn', function () {
        layer.open({
            type: 2,
            title: '编辑群聊',
            content: '/admin/groupchat/edit?group_id=' + talk.group_info.id,
            area: ['650px', '520px'],
        });
    })


    //群组管理
    $('body').on('click', '.manageGroupBtn', function () {
        $(this).addClass('layui-hide')
        $('.cancelManageGroupBtn').removeClass('layui-hide')
        // 用户复选框显示
        $('.groupUserList .g_checkbox').removeClass('layui-hide')
        // 全选、移除按钮显示
        $('.gManageUserBtn').removeClass('layui-hide')
    })

    //取消群组管理
    $('body').on('click', '.cancelManageGroupBtn', function () {
        $(this).addClass('layui-hide')
        $('.manageGroupBtn').removeClass('layui-hide')
        // 用户复选框显示、取消全部选中
        $('.groupUserList .g_checkbox').addClass('layui-hide')
        $('.groupUserList li input[type="checkbox"]').prop("checked", false)
        // 全选、移除按钮隐藏
        $('.gManageUserBtn').addClass('layui-hide')

    })

    //全选
    $('body').on('click', '.selectAllBtn', function () {
        $('.groupUserList li input[type="checkbox"]').prop("checked", true)
    })

    //取消全选
    $('body').on('click', '.notSelectAllBtn', function () {
        $('.groupUserList li input[type="checkbox"]').prop("checked", false)
    })

    //移除群成员
    $('body').on('click', '.removeSelectBtn', function () {
        var user_arr = [];
        $('.groupUserList li input[type="checkbox"]:checked').each(function () {
            user_arr.push($(this).parents('li').eq(0).data('user_id'));
        })
        if (user_arr.length < 1) {
            return layer.msg('请选择用户移除')
        }

        layer.confirm('确定要移除选中的成员吗？', function (index) {
            layer.load();
            $.ajax({
                type: 'POST',
                url: '/admin/groupchat/kick_user',
                data: {group_id: talk.group_info.id, user_ids: user_arr.join(',')},
                dataType: 'json',
                success: function (res) {
                    layer.closeAll("loading");
                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                            window.location.reload();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, status, error) {

                },
                complete: function (xhr, status) {
                    layer.closeAll("loading");
                }
            });
        });
    })


    window_click = 0;
    // 显示用户设置弹窗
    $('body').on('click', '.gManageBtn', function (ev) {
        var e = ev || window.event;
        e.stopPropagation();
        let $panel = $(this).next('.groupUserManageBtn');
        let user_role = $panel.parents('li').eq(0).data('role')
        let user_status = $panel.parents('li').eq(0).data('status');
        if (user_role == 2) {
            return;
        }

        // 显示弹窗
        if ($panel.html() == '') {
            $('.groupUserManageBtn').html('');
            let html = '';
            var bandHtml = '<p class="bandUserBtn">禁止发言</p>';
            if (user_status == 1) {
                bandHtml = '<p class="un_bandUserBtn">解除禁言</p>';
            }
            $panel.html(`
                <div class="manage_user">
                    <p class="setRoomManagerBtn ${user_role == 1 ? 'layui-hide' : ''}">设置房管</p>
                    <p class="cancelRoomManagerBtn ${user_role == 1 ? '' : 'layui-hide'}">取消房管</p>
                    <p class="kickOutGroupBtn">踢出群聊</p>` + bandHtml + `
                </div>`);
        }
    });

    // 主要是用户设置弹窗操作执行关闭问题
    $(window).click(function () {
        if (window_click == 1) {
            return false;
        } else {
            $('.groupUserManageBtn').html('');
        }
    });

    // 弹出面板上面操作不能关闭对话框
    $(".groupInfo").on('mousedown', '.groupUserManageBtn', function (e) {
        var ev = e || window.event;
        // ev.stopPropagation();
        window_click = 1;
    });

    // 弹出面板上面操作可以执行关闭对话框
    $(".groupInfo").on('mouseleave', '.groupUserManageBtn', function (e) {
        var ev = e || window.event;
        // ev.stopPropagation();
        window_click = 0;
    });


    //设置房管
    $('body').on('click', '.setRoomManagerBtn', function () {
        let panel_li = $(this).parents('li').eq(0);
        let user_id = panel_li.data('user_id');
        let user_name = panel_li.data('nick_name');
        if (user_id < 1) {
            return layer.msg('用户选择错误')
        }

        layer.confirm(`确定要将 “${user_name}” 设置为房管吗？`, function (index) {
            layer.load();
            $.ajax({
                type: 'POST',
                url: '/admin/groupchat/set_manage',
                data: {group_id: talk.group_info.id, user_id: user_id},
                dataType: 'json',
                success: function (res) {
                    layer.closeAll("loading");
                    if (res.code == 0) {
                        // 取消房管设置role角色为房管
                        panel_li.data('role', 1)
                        layer.msg(res.msg, {icon: 1,time:2000}, function () {
                            getGroupUser();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, status, error) {
                },
                complete: function (xhr, status) {
                    layer.closeAll("loading");
                }
            });
        });
    })

    //取消房管
    $('body').on('click', '.cancelRoomManagerBtn', function () {
        let panel_li = $(this).parents('li').eq(0);
        let user_id = panel_li.data('user_id');
        let user_name = panel_li.data('nick_name');
        if (user_id < 1) {
            return layer.msg('用户选择错误')
        }

        layer.confirm(`确定要将 “${user_name}” 取消房管吗？`, function (index) {
            layer.load();
            $.ajax({
                type: 'POST',
                url: '/admin/groupchat/cancel_manage',
                data: {group_id: talk.group_info.id, user_id: user_id},
                dataType: 'json',
                success: function (res) {
                    layer.closeAll("loading");
                    if (res.code == 0) {
                        // 取消房管设置role角色为用户
                        panel_li.data('role', 0)
                        layer.msg(res.msg, {icon: 1, time:2000}, function () {
                            getGroupUser();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, status, error) {
                },
                complete: function (xhr, status) {
                    layer.closeAll("loading");
                }
            });
        });
    })

    //踢出群聊
    $('body').on('click', '.kickOutGroupBtn', function () {
        let panel_li = $(this).parents('li').eq(0);
        let user_id = panel_li.data('user_id');
        let user_name = panel_li.data('nick_name');
        if (user_id < 1) {
            return layer.msg('用户选择错误')
        }

        layer.confirm(`确定要将 “${user_name}” 踢出群聊吗？`, function (index) {
            layer.load();
            $.ajax({
                type: 'POST',
                url: '/admin/groupchat/kick_user',
                data: {group_id: talk.group_info.id, user_ids: user_id},
                dataType: 'json',
                success: function (res) {
                    layer.closeAll("loading");
                    if (res.code == 0) {
                        panel_li.remove();
                        layer.msg(res.msg, {icon: 1, time: 2000});
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, status, error) {
                },
                complete: function (xhr, status) {
                    layer.closeAll("loading");
                }
            });
        });
    })


    // 撤回消息弹窗
    remove_msg_click = 0;
    // 显示用户设置弹窗
    $('body').on('click', '#imTalkList .anchor_send dd', function (ev) {
        var e = ev || window.event;
        e.stopPropagation();
        let $panel = $(this);
        // 显示弹窗
        $('.chatSetUser').remove();
        $('.removeMsg').remove();
        $panel.append(`<div class="remove_msg removeMsg">
                    <p class="removeMsgBtn">撤回</p>
                </div>`);

    });

    $('body').on('click', '#imTalkList .anchor_send .view_img', function (ev) {
        var e = ev || window.event;
        e.stopPropagation();
        let $panel = $(this);
        // 显示弹窗
        $('.chatSetUser').remove();
        $('.removeMsg').remove();
        $panel.append(`<div class="remove_msg removeMsg" style="width: 125px">
                    <p><a href="javascript:;" class="removeMsgBtn">撤回</a><a href="javascript:;"  class="img_view" style="margin-left:10px">查看图片</a></p>
                </div>`);

    });

    $('body').on('click', '#imTalkList .del_message .view_img', function (ev) {
        var e = ev || window.event;
        e.stopPropagation();
        let $panel = $(this);
        // 显示弹窗
        $('.chatSetUser').remove();
        $('.removeMsg').remove();
        $panel.append(`<div class="del_msg removeMsg" style="width: 125px">
                    <p><a href="javascript:;" class="del_message_btn">删除</a><a href="javascript:;"  class="img_view" style="margin-left:10px">查看图片</a></p>
                </div>`);

    });

    $('body').on('click', '#imTalkList .del_message dd', function (ev) {
        var e = ev || window.event;
        e.stopPropagation();
        let $panel = $(this);
        // 显示弹窗
        $('.chatSetUser').remove();
        $('.removeMsg').remove();
        $panel.append(`<div class="del_msg removeMsg">
                    <p class="del_message_btn">删除</p>
                </div>`);

    });


    // 主要是用户设置弹窗操作执行关闭问题
    $(window).click(function () {
        if (remove_msg_click == 1) {
            return false;
        } else {
            $('.removeMsg').remove();
        }
    });

    // 弹出面板上面操作不能关闭对话框
    $(".imTalkList").on('mousedown', 'dd', function (e) {
        var ev = e || window.event;
        // ev.stopPropagation();
        remove_msg_click = 1;
    });

    // 弹出面板上面操作可以执行关闭对话框
    $(".imTalkList").on('mouseleave', '.dd', function (e) {
        var ev = e || window.event;
        // ev.stopPropagation();
        remove_msg_click = 0;
    });


    // 聊天窗口用户设置弹窗
    chat_user_click = 0;
    // 显示用户设置弹窗
    /**
    $('body').on('click', '#imTalkList dt', function (ev) {
        var e = ev || window.event;
        e.stopPropagation();
        let $panel = $(this);
        let user_role = $panel.data('role')

        // 显示弹窗
        $('.chatSetUser').remove();
        $('.removeMsg').remove();
        $panel.append(`<div class="chat_set_user chatSetUser">
                     <p class="chatSetRoomManagerBtn ${user_role == 1 ? 'layui-hide' : ''}">设置房管</p>
                    <p class="chatCancelRoomManagerBtn ${user_role == 1 ? '' : 'layui-hide'}">取消房管</p>
                    <p class="chatKickOutGroupBtn">踢出群聊</p>
                    <p class="chatBandUserBtn">禁止发言</p>
                </div>`);

    });***/

    // 主要是用户设置弹窗操作执行关闭问题
    $(window).click(function () {
        if (chat_user_click == 1) {
            return false;
        } else {
            $('.chatSetUser').remove();
        }
    });

    // 弹出面板上面操作不能关闭对话框
    $(".imTalkList").on('mousedown', 'dt', function (e) {
        var ev = e || window.event;
        // ev.stopPropagation();
        chat_user_click = 1;
    });

    // 弹出面板上面操作可以执行关闭对话框
    $(".imTalkList").on('mouseleave', '.dt', function (e) {
        var ev = e || window.event;
        // ev.stopPropagation();
        chat_user_click = 0;
    });

    //查看图片
    $('body').on('click', '#imTalkList .img_view', function () {
        let panel_dl = $(this).parents('dl').eq(0);
        let src = panel_dl.data('image_url');
        if (src) {
            layer.photos({
                photos: {
                    "title": "",
                    "data": [{
                        "src": src,
                    }]
                }
                , shade: 0.01
                , closeBtn: 1
            });
        }

    });

    // 消息撤回
    $('body').on('click', '#imTalkList .removeMsgBtn', function () {
        let panel_dl = $(this).parents('dl').eq(0);
        let seq_id = panel_dl.data('seq');
        if (!seq_id) {
            return layer.msg('参数错误')
        }

        layer.load();
        $.ajax({
            type: 'POST',
            url: '/admin/groupchat/revoke_message',
            data: {group_id: talk.group_info.id, msg_id: seq_id},
            dataType: 'json',
            success: function (res) {
                layer.closeAll("loading");
                if (res.code == 0) {
                    // 撤回成功后，删除单条记录
                    panel_dl.remove()
                    layer.msg(res.msg, {icon: 1});
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            },
            error: function (xhr, status, error) {},
            complete: function (xhr, status) {
                layer.closeAll("loading");
            }
        });
    });

    // 消息删除
    $('body').on('click', '#imTalkList .del_message_btn', function () {
        let panel_dl = $(this).parents('dl').eq(0);
        let seq_id = panel_dl.data('seq');
        if (!seq_id) {
            return layer.msg('参数错误')
        }

        layer.load();
        $.ajax({
            type: 'POST',
            url: '/admin/groupchat/del_message',
            data: {group_id: talk.group_info.id, msg_id: seq_id},
            dataType: 'json',
            success: function (res) {
                layer.closeAll("loading");
                if (res.code == 0) {
                    // 撤回成功后，删除单条记录
                    panel_dl.remove()
                    layer.msg(res.msg, {icon: 1});
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            },
            error: function (xhr, status, error) {},
            complete: function (xhr, status) {
                layer.closeAll("loading");
            }
        });
    });

    // 聊天内容列表-设置房管
    $('body').on('click', '#imTalkList .chatSetRoomManagerBtn ', function () {
        let panel_dl = $(this).parents('dl').eq(0);
        let user_id = panel_dl.data('uid');
        let user_name = panel_dl.data('nick_name');
        if (user_id < 1) {
            return layer.msg('用户选择错误')
        }

        layer.confirm(`确定要将 “${user_name}” 设置为房管吗？`, function (index) {
            layer.load();
            $.ajax({
                type: 'POST',
                url: '/admin/groupchat/set_manage',
                data: {group_id: talk.group_info.id, user_id: user_id},
                dataType: 'json',
                success: function (res) {
                    layer.closeAll("loading");
                    if (res.code == 0) {
                        // 取消房管设置role角色为房管
                        panel_dl.data('role', 1)
                        layer.msg(res.msg, {icon: 1, time:2000}, function () {
                            getGroupUser();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, status, error) {
                },
                complete: function (xhr, status) {
                    layer.closeAll("loading");
                }
            });
        });
    })

    //取消房管
    $('body').on('click', '#imTalkList .chatCancelRoomManagerBtn', function () {
        let panel_dl = $(this).parents('dl').eq(0);
        let user_id = panel_dl.data('uid');
        let user_name = panel_dl.data('nick_name');
        if (user_id < 1) {
            return layer.msg('用户选择错误')
        }

        layer.confirm(`确定要将 “${user_name}” 取消房管吗？`, function (index) {
            layer.load();
            $.ajax({
                type: 'POST',
                url: '/admin/groupchat/cancel_manage',
                data: {group_id: talk.group_info.id, user_id: user_id},
                dataType: 'json',
                success: function (res) {
                    layer.closeAll("loading");
                    if (res.code == 0) {
                        // 取消房管设置role角色为用户
                        panel_dl.data('role', 0)
                        layer.msg(res.msg, {icon: 1, time:2000}, function () {
                            getGroupUser();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, status, error) {
                },
                complete: function (xhr, status) {
                    layer.closeAll("loading");
                }
            });
        });
    })

    //踢出群聊
    $('body').on('click', '#imTalkList .chatKickOutGroupBtn', function () {
        let panel_dl = $(this).parents('dl').eq(0);
        let user_id = panel_dl.data('uid');
        let user_name = panel_dl.data('nick_name');
        if (user_id < 1) {
            return layer.msg('用户选择错误')
        }

        layer.confirm(`确定要将 “${user_name}” 踢出群聊吗？`, function (index) {
            layer.load();
            $.ajax({
                type: 'POST',
                url: '/admin/groupchat/kick_user',
                data: {group_id: talk.group_info.id, user_ids: user_id},
                dataType: 'json',
                success: function (res) {
                    layer.closeAll("loading");
                    if (res.code == 0) {
                        panel_dl.remove();
                        layer.msg(res.msg, {icon: 1, time: 2000}, function () {
                            getGroupUser();
                        });
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                },
                error: function (xhr, status, error) {
                },
                complete: function (xhr, status) {
                    layer.closeAll("loading");
                }
            });
        });
    })


    //踢出群聊
    $('body').on('click', '#imTalkList .chatBandUserBtn', function () {
        let panel_dl = $(this).parents('dl').eq(0);
        let user_id = panel_dl.data('uid');
        let user_name = panel_dl.data('nick_name');
        if (user_id < 1) {
            return layer.msg('用户选择错误')
        }

        var html = '';
        html += '<div style="align-content: center; margin-top:10px"><form class="layui-form" action="" class="layui-form layui-form-pane" id="sbumitForm">';
        html += '<style>';
        html += '.layui-layer-content {\n' +
            '            position: relative;\n' +
            '            padding: 10px;\n' +
            '            line-height: 24px;\n' +
            '            word-break: break-all;\n' +
            '            overflow: hidden;\n' +
            '            font-size: 14px;\n' +
            '            overflow-x: hidden;\n' +
            '            overflow-y: auto;\n' +
            '            position: relative;\n' +
            '        }';
        html += '</style>';
        html += '<input type="hidden" name="user_id" value="' + user_id + '">';
        html += '<input type="hidden" name="group_id" value="' + talk.group_info.id + '">';
        html += '<div class="layui-form-item">\n' +
            '                <label class="layui-form-label">用户昵称</label>\n' +
            '                <div class="layui-input-block">\n' +
            '                    <input type="text" name="name" value="' + user_name + '"  class="layui-input" placeholder="用户昵称" autocomplete="off" readonly="true">\n' +
            '                </div>\n' +
            '            </div>';
        html += '<div class="layui-form-item">\n' +
            '                            <label class="layui-form-label">禁言时间:</label>\n' +
            '                            <div class="layui-input-block">\n' +
            '                                <select name="time">\n' +
            '                                    <option value="10">10分钟</option>\n' +
            '                                    <option value="30">30分钟</option>\n' +
            '                                    <option value="120">2个小时</option>\n' +
            '                                    <option value="360">6个小时</option>\n' +
            '                                    <option value="1440">1天</option>\n' +
            '                                    <option value="10080">7天</option>\n' +
            '                                    <option value="-1">永久</option>\n' +
            '                                </select>\n' +
            '                            </div>\n' +
            '                        </div>';
        html += '<div class="layui-form-item">\n' +
            '                            <label class="layui-form-label">禁言理由:</label>\n' +
            '                            <div class="layui-input-block">\n' +
            '                                <select name="reason">\n' +
            '                                    <option value="广告营销诈骗">广告营销诈骗</option>\n' +
            '                                    <option value="低俗色情">低俗色情</option>\n' +
            '                                    <option value="不实信息">不实信息</option>\n' +
            '                                    <option value="辱骂谩骂">辱骂谩骂</option>\n' +
            '                                    <option value="涉政言论">涉政言论</option>\n' +
            '                                    <option value="违法有害信息">违法有害信息</option>\n' +
            '                                    <option value="其他">其他</option>\n' +
            '                                </select>\n' +
            '                            </div>\n' +
            '                        </div>';
        html += '</form></div>';
        layer.confirm(html, {area: ['420px', '390px'], title: '禁言发言'}, function (index) {

            $.ajax({
                type: "POST",//请求方式
                url: '/admin/groupchat/ban_user', //请求地址
                dataType: "json",//返回的数据类型
                data: $("#sbumitForm").serialize(),
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            //window.location.reload();
                            getGroupUser();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                }
            });
        });

        layui.form.render();
    })

    //解除发言
    $('body').on('click', '.un_bandUserBtn', function () {
        let panel_li = $(this).parents('li').eq(0);
        let user_id = panel_li.data('user_id');
        let user_name = panel_li.data('nick_name');
        if (user_id < 1) {
            return layer.msg('用户选择错误')
        }

        layer.confirm('确认要解除禁言吗？', {icon: 6}, function (index) {
            $.ajax({
                type: "POST",//请求方式
                url: '/admin/groupchat/un_banned_user', //请求地址
                dataType: "json",//返回的数据类型
                data: {user_id:user_id, group_id: talk.group_info.id},
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            //window.location.reload();
                            getGroupUser();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                }
            });
        });
    });

    //禁止发言
    $('body').on('click', '.bandUserBtn', function () {
        let panel_li = $(this).parents('li').eq(0);
        let user_id = panel_li.data('user_id');
        let user_name = panel_li.data('nick_name');
        if (user_id < 1) {
            return layer.msg('用户选择错误')
        }


        var html = '';
        html += '<div style="align-content: center; margin-top:10px"><form class="layui-form" action="" class="layui-form layui-form-pane" id="sbumitForm">';
        html += '<style>';
        html += '.layui-layer-content {\n' +
            '            position: relative;\n' +
            '            padding: 10px;\n' +
            '            line-height: 24px;\n' +
            '            word-break: break-all;\n' +
            '            overflow: hidden;\n' +
            '            font-size: 14px;\n' +
            '            overflow-x: hidden;\n' +
            '            overflow-y: auto;\n' +
            '            position: relative;\n' +
            '        }';
        html += '</style>';
        html += '<input type="hidden" name="user_id" value="' + user_id + '">';
        html += '<input type="hidden" name="group_id" value="' + talk.group_info.id + '">';
        html += '<div class="layui-form-item">\n' +
            '                <label class="layui-form-label">用户昵称</label>\n' +
            '                <div class="layui-input-block">\n' +
            '                    <input type="text" name="name" value="' + user_name + '"  class="layui-input" placeholder="用户昵称" autocomplete="off" readonly="true">\n' +
            '                </div>\n' +
            '            </div>';
        html += '<div class="layui-form-item">\n' +
            '                            <label class="layui-form-label">禁言时间:</label>\n' +
            '                            <div class="layui-input-block">\n' +
            '                                <select name="time">\n' +
            '                                    <option value="10">10分钟</option>\n' +
            '                                    <option value="30">30分钟</option>\n' +
            '                                    <option value="120">2个小时</option>\n' +
            '                                    <option value="360">6个小时</option>\n' +
            '                                    <option value="1440">1天</option>\n' +
            '                                    <option value="10080">7天</option>\n' +
            '                                    <option value="-1">永久</option>\n' +
            '                                </select>\n' +
            '                            </div>\n' +
            '                        </div>';
        html += '<div class="layui-form-item">\n' +
            '                            <label class="layui-form-label">禁言理由:</label>\n' +
            '                            <div class="layui-input-block">\n' +
            '                                <select name="reason">\n' +
            '                                    <option value="广告营销诈骗">广告营销诈骗</option>\n' +
            '                                    <option value="低俗色情">低俗色情</option>\n' +
            '                                    <option value="不实信息">不实信息</option>\n' +
            '                                    <option value="辱骂谩骂">辱骂谩骂</option>\n' +
            '                                    <option value="涉政言论">涉政言论</option>\n' +
            '                                    <option value="违法有害信息">违法有害信息</option>\n' +
            '                                    <option value="其他">其他</option>\n' +
            '                                </select>\n' +
            '                            </div>\n' +
            '                        </div>';
        html += '</form></div>';
        layer.confirm(html, {area: ['420px', '390px'], title: '禁言发言'}, function (index) {

            $.ajax({
                type: "POST",//请求方式
                url: '/admin/groupchat/ban_user', //请求地址
                dataType: "json",//返回的数据类型
                data: $("#sbumitForm").serialize(),
                //请求成功
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                            //window.location.reload();
                            getGroupUser();
                        });
                    } else if (data.code == 1000) {
                        layer.msg(data.msg, {icon: 2, time: 3000}, function () {
                            //window.location.reload();
                            getGroupUser();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                //请求失败，包含具体的错误信息
                error: function (e) {
                }
            });
        });

        layui.form.render();
    })


    exports("groupchat", {});
});
